﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FormControllers;
using AgencyEntityLib.BaseEntity;
using Ecopsy.Tools;
using Ecopsy.DataTier.SqlLibrary;
using SqlLibrary;

public partial class iCRM_ContactFaces : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ctlContactFaces1.KeyPref = this.GetType().ToString();
        ctlContactFaces1.ShowHead = true;
        ctlContactFaces1.PageSize = 15;

        if (!IsPostBack)
        {
            DataBind(); 
        }
        OnInit();
    }



    protected void OnInit()
    {
        ctlFilterSave1.SaveOnClick = ctlFilterSave1_SaveOnClick;
        ctlFilterSave1.OkOnClick = ctlFilterSave1_OkOnClick;
        ctlFilterSave1.FilterType = Filter.FilterType.ContactFaces;
        ctlFilterSave1.AddKey = string.Empty ;



        ctlFilterBar1.OnFindClik = ctlFilterBar1_OnFindClik;
        ctlFilterBar1.OnFilterListClik = ctlFilterBar1_OnFilterListClik;
        ctlFilterBar1.OnFilterSaveClik = ctlFilterBar1_OnFilterSaveClik;
        ctlFilterBar1.HintServiceMethod = "GetContactFacesParams";


        ctlFilterList1.OnApp_Click = ctlFilterList1_OnApp_Click;
        ctlFilterList1.FilterType = Filter.FilterType.ContactFaces; 
        ctlFilterList1.AddKey = string.Empty;

        ModalPopupext_FilterSave.DataBind();
        ModalPopupext_FilterList.DataBind();
    }

    private bool ctlFilterList1_OnApp_Click(ListWhere _Where)
    {
        ctlContactFaces1.Where = _Where;
        ctlFilterBar1.Lexeme = _Where.ListLoadStatment.Lexeme;

        ctlFilterSave1.DataBind();
        ctlFilterBar1.DataBind();
        ctlContactFaces1.DataBind();
        return true;
    }

    private bool ctlFilterBar1_OnFilterSaveClik()
    {
        ModalPopupext_FilterSave.Show();
        return true;
    }

    private bool ctlFilterBar1_OnFilterListClik()
    {
        ctlFilterList1.MyDataBind();
        ModalPopupext_FilterList.Show();
        return true;
    }

    private ListWhere ctlFilterSave1_SaveOnClick()
    {
        return (ListWhere)ctlContactFaces1.Where.Clone();
    }

    private bool ctlFilterSave1_OkOnClick()
    {
        ModalPopupext_FilterSave.DataBind();
        ModalPopupext_FilterSave.Hide();
        return true;
    }

    private bool ctlFilterBar1_OnFindClik(string sFindStr)
    {

        ctlContactFaces1.Lexeme = ctlFilterBar1.Lexeme;
        ctlContactFaces1.DataBind();
        return true;
    }


    #region SavePanel

    protected string GetTargetControlID_FilterSave()
    {
        return ctlFilterBar1.BtnAddFilter_ClientID;
    }

    public string GetOkControlID_FilterSave()
    {

        return ctlFilterSave1.btnSave_ClientID;
    }

    public string GetCancelControlID_FilterSave()
    {

        return ctlFilterSave1.BtnCancel_ClientID;
    }

    #endregion

    #region ListPanel

    protected string GetTargetControlID_FilterList()
    {
        return ctlFilterBar1.BtnFilterList_ClientID;
    }

    public string GetOkControlID_FilterList()
    {

        return ctlFilterList1.btnSave_ClientID;
    }

    public string GetCancelControlID_FilterList()
    {

        return ctlFilterList1.BtnCancel_ClientID;
    }

    #endregion


    protected string TxtSerchValue
    {
        get { return ctlContactFaces1.Lexeme; }
    }
   
    

    protected void OnDeleteClick(object sender, EventArgs e)
    {
        ImageButton btn =(ImageButton) sender ;
        wsFace ws = (wsFace)GlobalConstants.CurrentAgency.WS_FactoryList[WS_FactoryList.wsKey_Face];
        ContactFace fc= ws.GetContactFace(btn.CommandArgument);
        fc.DestroyMySelf();
        fc.Save();        

    }
    
}
